package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperComment;
import com.ruoyi.system.domain.SuperMerchantReply;
import com.ruoyi.system.service.ISuperMerchantReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商家回复评论Controller
 * 
 * @author xjf
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/comment/reply")
public class SuperMerchantReplyController extends BaseController
{
    @Autowired
    private ISuperMerchantReplyService superMerchantReplyService;

    /**
     * 查询商家回复评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:reply:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperMerchantReply superMerchantReply, Long productId)
    {
        // 如果前端传了 productId，就塞到 comment 里
        if (productId != null) {
            if (superMerchantReply.getComment() == null) {
                superMerchantReply.setComment(new SuperComment());
            }
            superMerchantReply.getComment().setProductId(productId);
        }

        startPage();
        List<SuperMerchantReply> list = superMerchantReplyService.selectSuperMerchantReplyList(superMerchantReply);
        return getDataTable(list);
    }
    /**
     * 导出商家回复评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:reply:export')")
    @Log(title = "商家回复评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperMerchantReply superMerchantReply)
    {
        List<SuperMerchantReply> list = superMerchantReplyService.selectSuperMerchantReplyList(superMerchantReply);
        ExcelUtil<SuperMerchantReply> util = new ExcelUtil<SuperMerchantReply>(SuperMerchantReply.class);
        util.exportExcel(response, list, "商家回复评论数据");
    }

    /**
     * 获取商家回复评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:reply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superMerchantReplyService.selectSuperMerchantReplyById(id));
    }

    /**
     * 新增商家回复评论
     */
    @PreAuthorize("@ss.hasPermi('comment:reply:add')")
    @Log(title = "商家回复评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperMerchantReply superMerchantReply)
    {
        return toAjax(superMerchantReplyService.insertSuperMerchantReply(superMerchantReply));
    }

    /**
     * 修改商家回复评论
     */
    @PreAuthorize("@ss.hasPermi('comment:reply:edit')")
    @Log(title = "商家回复评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperMerchantReply superMerchantReply)
    {
        return toAjax(superMerchantReplyService.updateSuperMerchantReply(superMerchantReply));
    }

    /**
     * 删除商家回复评论
     */
    @PreAuthorize("@ss.hasPermi('comment:reply:remove')")
    @Log(title = "商家回复评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superMerchantReplyService.deleteSuperMerchantReplyByIds(ids));
    }
}
